package org.bluedream.core.module.controller.depItem;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.bluedream.comm.base.BaseController;
import org.bluedream.core.config.advice.RsaSecurityParameter;
import org.bluedream.core.module.entity.depItem.DepItemUser;
import org.bluedream.core.module.service.depItem.DepItemUserService;
import org.bluedream.core.utils.configUtil.GoalConfigUtil;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;

/**
 * @ClassName depItemUserUserController
 * @Description TODO
 * @Author Administrator
 * @Data 2022/5/26 13:39
 * @Version
 */
@Controller
@RequestMapping(value = "${adminPath}/depItemUser")
public class DepItemUserController extends BaseController {
    @Resource
    private DepItemUserService depItemUserService;

    @ModelAttribute
    public DepItemUser get(String id){
        return depItemUserService.getById(id);
    }

    @RequiresPermissions("depItemUser:view")
    @RequestMapping(value = {"/list" , ""})
    public String list(DepItemUser entity, Model model){
        model.addAttribute("pageSize" , GoalConfigUtil.getValueByKey("sys.page.size"));
        model.addAttribute("depItemUser" , entity);
        return "module/depItem/depItemUserList";
    }

    @RequiresPermissions("depItemUser:view")
    @RequestMapping("/form")
    public String form(DepItemUser entity, Model model){
        model.addAttribute("depItemUser" , entity);
        return "module/depItem/depItemUserForm";
    }

    @RequiresPermissions("depItemUser:view")
    @RequestMapping("/findPage")
    @ResponseBody
    public IPage<DepItemUser> findPage(@RsaSecurityParameter DepItemUser entity){
        return depItemUserService.findPage(entity);
    }

    @RequiresPermissions("depItemUser:edit")
    @RequestMapping("/save")
    @ResponseBody
    public String save(DepItemUser entity){
        boolean flag = depItemUserService.save(entity);
        if (flag){
            return "用户保存成功";
        }
        return "用户保存失败";
    }
}